import tkinter,threading,time
from tkinter import messagebox
import mysql.connector,os,shutil,requests
import operate_fun
 
def login():
    username = username_entry.get()
    password = password_entry.get()
    mydb = mysql.connector.connect(host="43.161.240.94",user="hcecpod_com",passwd="Xcd9sMZ9DMBBkbMf",database="hcecpod_com")
    mycursor = mydb.cursor()
    mycursor.execute("select role from setting_user where username = '"+username+"' and password = '"+password+"'")
    myresult = mycursor.fetchone()
    if myresult:
        login_window.destroy()
        main_window(username,myresult[0])
    else:
        messagebox.showerror("登录失败", "用户名或密码错误")
    # login_window.destroy()
    # main_window('乔月','设计')
        
def task_query_show(username,role):
    my_text=operate_fun.task_query(username,role)
    T1.config(text=my_text)
   
 
def main_window(username,role):
    win = tkinter.Tk()
    win.iconbitmap('logo.ico')
    win.title("小成文件协作 v2.1")
    win.geometry("600x400+200+50")
    L1 = tkinter.Label(win,text='任务看板：',anchor="w", justify="left", font=('微软雅黑', 10))
    L1.place(x=8,y=20,width=150,height=26)

    global T1
    text_content = f"请点击任务看板更新按钮进行数据刷新\n"
    T1 = tkinter.Label(win,text=text_content,anchor="nw", justify="left", wraplength=550,bg='white',fg='#3d1f02',font="微软雅黑 11 bold")
    T1.place(x=10,y=55,width=580,height=200)

    B2=tkinter.Button(win, text='任务看板更新', bg='white', font=('微软雅黑', 10),command=lambda:task_query_show(username,role))
    B2.place(x=10,y=330,width=150,height=26)
    
    B2=tkinter.Button(win, text='拷贝关联文件', bg='white', font=('微软雅黑', 10),command=lambda:operate_fun.task_files_copy(username,role))
    B2.place(x=200,y=330,width=150,height=26)

    B2=tkinter.Button(win, text='完成任务交接', bg='white', font=('微软雅黑', 10),command=lambda:operate_fun.over_task_submit(username,role))
    B2.place(x=390,y=330,width=150,height=26)
    win.mainloop()
    

# 创建登录窗口
login_window = tkinter.Tk()
login_window.iconbitmap('logo.ico')
login_window.title("登录验证")
login_window.geometry("300x200")
 
# 创建用户名和密码输入框
tkinter.Label(login_window, text="用户名:").pack()
username_entry = tkinter.Entry(login_window)
username_entry.pack()
tkinter.Label(login_window, text="密码:").pack()
password_entry = tkinter.Entry(login_window, show="*")  # 显示星号代替密码字符
password_entry.pack()
 
# 创建登录按钮并绑定登录函数
login_button = tkinter.Button(login_window, text="登录", command=login)
login_button.pack(pady=20)
 
login_window.mainloop()